﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MethodWorx.CMS.Workflow;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Services;

namespace MethodWorx.CMS.UI.Models
{
    public class EditWorkflowModel
    {
        public Page Page { get; set; }
        public EditWorkflowModel(Page page, ContentService content)
        {
            this.Workflows = page.GetWorkflowConfiguration(true);
            this.Page = page;
            this.SharedPages = content.GetPagesByTemplate(this.Page.Template.Name);
        }


        public string CurrentWorkflowName { get; set; }
        public WorkflowConfiguration[] Workflows { get; set; }

        public List<IWorkflowComponent> Components { get; set; }
        public IEnumerable<Page> SharedPages { get; set; }
        public WorkflowConfiguration CurrentWorkflow
        {
            get
            {
                if(!string.IsNullOrEmpty(this.CurrentWorkflowName))
                    return this.Workflows.FirstOrDefault(w => w.Name.ToLower() == this.CurrentWorkflowName.ToLower()) ?? this.Workflows.First();
                else
                {
                    return this.Workflows.FirstOrDefault();
                }
            }
        }
       
    }
}